
/**
 * 项目配置文件加载
 * 
 * 优先加载执行命令中的 [-c xx.json] 指定配置文件
 * 其次根据环境变量加载相应环境配置文件
 */
const logger = require('../log')('config')
const argv = require('minimist')(process.argv.slice(2));
const fs = require("fs");

let config = {};
if (argv['c']) {
    config = JSON.parse(fs.readFileSync(argv['c']));
}

const development = require('./env/development.json')
const test = require('./env/test.json')
const production = require('./env/production.json')

// 默认配置
const defaults = {
    'port': 3000
}

logger.debug('config env is: ' + process.env.NODE_ENV);

module.exports = {
    development: Object.assign({}, defaults, development, config),
    test: Object.assign({}, defaults, test, config),
    production: Object.assign({}, defaults, production, config)
}[process.env.NODE_ENV || 'development']